package dao;

import org.apache.ibatis.annotations.*;
import pojo.DoctorWork;
import pojo.Work;

import java.util.List;

@Mapper
public interface WorkMapper {

    @Select("SELECT day, weekday, status, create_by, create_time FROM work_plan")
    List<Work> findAll();


    @Update("UPDATE work_plan SET weekday=#{weekday}, status=#{status}, " +
            "create_by=#{createBy}, create_time=#{createTime} " +
            "WHERE day=#{day}")
    int updateWork(Work work);

    @Delete("DELETE FROM work_plan WHERE day=#{day}")
    int deleteWork(String day);

    @Select("SELECT dw.* FROM doctor_work dw, work_plan wp " +
            "WHERE dw.day=wp.day AND wp.status=1 AND dw.day IN (${week})")
    List<DoctorWork> getWorkByWeek(String week);

    // 新增根据日期查询单个工作计划的方法
    @Select("SELECT * FROM work_plan WHERE day = #{day}")
    Work selectById(String day);

    @Insert("INSERT INTO work_plan(day, weekday, status, create_by, create_time) " +
            "VALUES(#{day}, #{weekday}, #{status}, #{createBy}, #{createTime})")
    int addWork(Work work);
}